﻿@using SCMS.Resource
@model SCMS.UI.Models.ViewOR
@{
    ViewBag.Title = Resources.Global_String_OrderRequest;
}
<div class="partialViewCard">
    <div class="partialViewCardHeader">
        <h3>
            @Resources.Global_String_OR: @Model.ORRefNo</h3>
    </div>
    @if (Model.CanEdit)
    {
        <center>
            @Ajax.ActionLink(Resources.OrderRequest_AddPPItems2OR_EditOR, "Index", new { id = "EditOR" }, new AjaxOptions
            {
                OnBegin = string.Format("ShowDialogue('{0}')", Resources.OrderRequest_AddPPItems2OR_EditOR),
                UpdateTargetId = "popup-page",
                LoadingElementId = "popup-loading",
                Url = Url.Action("EditOrderRequest/" + Model.EntityOR.Id),
                OnSuccess = "CenterPopup"
            }) |
            @Ajax.ActionLink(Resources.OrderRequest_String_DeleteOR, "Index", new { id = "DeleteOR" }, new AjaxOptions
            {
                UpdateTargetId = "requestDiv",
                LoadingElementId = "loading",
                Url = Url.Action("DeleteOrderRequest/" + Model.EntityOR.Id),
                Confirm = string.Format(Resources.Global_String_ConfirmDelete, Model.EntityOR.RefNumber),
                OnSuccess = "usermsg('" + Resources.OrderRequest_String_SuccessMsg + "');if (document.getElementById('table') != null) {initSorter();sorter.size(20);}"
            })
        </center>
    }
    else if(Model.CanApprove)
    {
        string linkText = null;
        string actionName = null;
        if (Model.EntityOR.IsReviewed == true && Model.EntityOR.IsAuthorized == false && Model.EntityOR.IsRejected != true)
        {
            linkText = Resources.OrderRequest_String_AuthorizeOrderRequest;
            actionName = "LoadOrderRequestForAuth";
        }
        else if (Model.EntityOR.IsApproved && Model.EntityOR.IsReviewed == false && Model.EntityOR.IsRejected != true)
        {
            linkText = Resources.OrderRequest_String_ReviewOrderRequest;
            actionName = "LoadOrderRequest";
        }
        else if (Model.EntityOR.IsSubmitted && !Model.EntityOR.IsApproved && Model.EntityOR.IsRejected != true)
        {
            linkText = Resources.OrderRequest_String_ApproveOrderRequest;
            actionName = "LoadOrderRequestForApproval";
        }
        if(linkText != null)
        {
            <center id="canApprove">
                @Ajax.ActionLink(linkText, actionName, "RequestReview", new { id = "EditOR" }, new AjaxOptions
                {
                    OnBegin = "ShowDialogueOR('" + linkText + ": " + Model.EntityOR.RefNumber + "')",
                    UpdateTargetId = "popup-page",
                    LoadingElementId = "popup-loading",
                    Url = Url.Action(actionName + "/" + Model.EntityOR.Id, "RequestReview"),
                    OnSuccess = "CenterPopupOR();document.getElementById('canApprove').innerHTML ='&nbsp;';"
                }) 
            </center>
        }
    }
    else
    {
        <br />
    }
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th align="center" width="33.3%">
                @Resources.Global_String_RefNo
            </th>
            <th align="center" width="33.3%">
                @Resources.Global_String_Date
            </th>
            <th align="center" width="33.3%">
                @Resources.Global_String_ORCurrency
            </th>
        </tr>
        <tr class="gridodd">
            <td align="center">
                @Model.ORRefNo
            </td>
            @if (UserContext.HasPermission(StandardPermissionProvider.BackDateDocument))
            { 
                <td align="center" title="@Resources_frank.OrderRequest_BackDateOR_BackDateOR" style="cursor: pointer;" onclick="ShowDialogue('@Resources_frank.OrderRequest_BackDateOR_BackDateOR :: @Model.EntityOR.RefNumber');sendRequest('/OrderRequest/BackDateOR/@Model.EntityOR.Id', 'popup-page', 'popup-loading');CenterPopup();">
                    @Model.IssueDate.ToString("dd/MM/yyyy")
                </td>
            }
            else
            {
                <td align="center">
                    @Model.IssueDate.ToString("dd/MM/yyyy")
                </td>
            }
            <td align="center">
                @Model.curency
                <input type="hidden" id="currencyId" name="currencyId" value="@Model.EntityOR.CurrencyId" />
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">
                @Resources.Budget_CreateProject_ProjectName
            </th>
            <th align="center">
                @Resources.Budget_CategoryList_ProjectNo
            </th>
            <th align="center">
                @Resources.Budget_CategoryList_Donor
            </th>
        </tr>
        <tr class="gridodd">
            <td align="center">
                @Model.EntityOR.ProjectDonor.Project.Name
            </td>
            <td align="center">
                @Model.EntityOR.ProjectDonor.ProjectNumber
            </td>
            <td align="center">
                @Model.Donor
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">
                @Resources.OrderRequest_EditOrderRequest_RequestedDeliveryDate
            </th>
            <th align="center">
                @Resources.OrderRequest_EditOrderRequest_RequestedDeliveryDestination
            </th>
            <th align="center">
                @Resources.OrderRequest_EditOrderRequest_FinalDeliveryDestination
            </th>
        </tr>
        <tr class="gridodd">
            <td align="center">
                @Model.RequestDate.ToString("dd/MM/yyyy")
            </td>
            <td align="center">
                @Model.RDD
            </td>
            <td align="center">
                @Model.FDD
            </td>
        </tr>
    </table>
    @if (Model.CanEdit)
    {
        @Html.Raw("<br />&nbsp;&nbsp;&nbsp;")
        @Ajax.ActionLink(Resources.OrderRequest_AddNewItem4OR_AddNewItem, "Index", new { id = "LoadRequestItem" }, new AjaxOptions
   {
       OnBegin = string.Format("ShowDialogue('{0}')", Resources.OrderRequest_AddNewItem4OR_AddNewItem),
       UpdateTargetId = "popup-page",
       LoadingElementId = "popup-loading",
       Url = Url.Action("AddItemInEditMode/" + Model.EntityOR.Id),
       OnSuccess = "ClearFormById('#' + 'frmORItem');CenterPopup();"
   })
    }
    <br />
    &nbsp;&nbsp; @Resources.OrderRequest_ViewOrderRequestItems_ItemsText
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th style="width: 5%; text-align: center;">
                #
            </th>
            <th style="width: 15%;">
                @Resources.Global_String_Item
            </th>
            <th style="width: 20%;">
                @Resources.Global_String_Description
            </th>
            <th style="width: 10%;">
                @Resources.Global_String_Unit
            </th>
            <th style="width: 5%; text-align: center;">
                @Resources.Global_String_Qty
            </th>
            <th style="width: 10%;">
                @Resources.OrderRequest_AddItemInEditMode_EstUnitPrice
            </th>
            <th style="width: 10%;">
                @Resources.OrderRequest_AddItemInEditMode_EstTotalPrice
            </th>
            <th style="width: 10%;">
                @Resources.Global_String_PN
            </th>
            <th style="width: 5%; text-align: center;">
                @Resources.Global_String_BL
            </th>
            <th style="width: 10%;">
                @Resources.Global_String_Remarks
            </th>
            @if (Model.CanEdit)
            {
                <th>
                    @Resources.Global_String_Manage
                </th>
            }
        </tr>
        @{int count = 0;}
        @foreach (var item in Model.ORDetails)
        {
            count = count + 1;
            <tr class="gridodd">
                <td align="center">
                    @count
                </td>
                <td>
                    @item.ItemName
                </td>
                <td>
                    @item.EntityORDetails.ItemDescription
                </td>
                <td align="center">
                    @item.UnityMessure
                </td>
                <td align="center">
                    @item.Quantity
                </td>
                <td align="right">
                    @Html.DisplayFor(m => item.EstmatedUnityPrice)
                </td>
                <td align="right">
                    @Html.DisplayFor(m => item.EstmatedTotalPrice)
                </td>
                <td align="center">
                    @item.ProjectNo
                </td>
                <td align="center">
                    @item.BudgetLine
                </td>
                <td>
                    @item.Remarks
                </td>
                <td>
                    @if (Model.CanEdit)
                    { 
                        @Ajax.ActionLink(Resources.Global_String_Edit, "Index", new { id = "EditItem" }, new AjaxOptions
                   {
                       OnBegin = string.Format("ShowDialogue('{0}')", Resources.OrderRequest_String_EditORItem),
                       UpdateTargetId = "popup-page",
                       LoadingElementId = "popup-loading",
                       Url = Url.Action("EditItemInEditMode/" + item.EntityORDetails.Id),
                       OnSuccess = "ComputeTotals();CenterPopup();"
                   }) 
                        @Html.Raw("&nbsp;|&nbsp;") 
                        @Ajax.ActionLink(Resources.Global_String_Remove, "Index", new { id = "RemoveItem" }, new AjaxOptions
                   {
                       UpdateTargetId = "requestDiv",
                       LoadingElementId = "loading",
                       Url = Url.Action("RemoveItemInEditMode/" + item.EntityORDetails.Id),
                       Confirm = string.Format(Resources.Global_String_ConfirmDelete, item.ItemName),
                       OnSuccess = string.Format("usermsg('{0}');", Resources.OrderRequest_String_DeletedItemMsg)
                   })
                    }
                </td>
            </tr>
        }
        <tr>
            <td colspan="3" class="gridheader" align="right">
                @Resources.OrderRequest_String_CurrencyOfOrderRequest &nbsp;
            </td>
            <td align="center">
                @Model.curency
            </td>
            <td class="gridheader" colspan="2" align="right">
                @Resources.Global_String_Total &nbsp;
            </td>
            <td align="right">
                <b>@Html.DisplayFor(m => m.TotalCost)</b>
            </td>
            @if (Model.CanEdit)
            {
                <td colspan="4" class="gridheader">
                    &nbsp;@Resources.OrderRequest_String_ORValue
                </td>
            }
            else
            { 
                <td colspan="3" class="gridheader">
                    &nbsp;@Resources.OrderRequest_String_ORValue
                </td>
            }
        </tr>
        <tr>
            <td colspan="3" class="gridheader" align="right">
                @Resources.Global_String_MasterBudgetCurrency &nbsp;
            </td>
            <td align="center">
                @ViewBag.MBCurrency
            </td>
            <td class="gridheader" colspan="2" align="right">
                @Resources.Global_String_Total &nbsp;
            </td>
            <td align="right">
                <b>@Html.DisplayFor(m => m.MBValue)</b>
            </td>
            @if (Model.CanEdit)
            {
                <td colspan="4" class="gridheader">
                    &nbsp;@Resources.OrderRequest_String_ORValue
                </td>
            }
            else
            { 
                <td colspan="3" class="gridheader">
                    &nbsp;@Resources.OrderRequest_String_ORValue
                </td>
            }
        </tr>
        <tr>
            @if (Model.CanEdit)
            {
                <td colspan="11" rowspan="3" align="left" valign="top">
                    <b>@Resources.Global_String_AdditionalRemarks:</b><br />
                    @Model.EntityOR.Remarks
                </td>
            }
            else
            { 
                <td colspan="10" rowspan="3" align="left" valign="top">
                    <b>@Resources.Global_String_AdditionalRemarks:</b><br />
                    @Model.EntityOR.Remarks
                </td>
            }
        </tr>
        <tr>
        </tr>
        <tr>
        </tr>
    </table>
    <br />
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <td width="16%">
                @Resources.Approver_ApproverList_Authorization
            </td>
            <td width="21%">
                @Resources.Global_String_Requester
            </td>
            <td width="21%">
                @Resources.Global_String_ApprovedBy
            </td>
            <td width="21%">
                @Resources.Global_String_FinanceReviewOfBL
            </td>
            <td width="21%">
                @Resources.Global_String_AuthorizedByManager
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Name:
            </td>
            <td>
                @Model.PreparedBy.Person.FirstName
                @Html.Raw("&nbsp;")
                @Model.PreparedBy.Person.OtherNames
            </td>
            <td>
                @if (Model.EntityOR.Staff != null)
                { 
                    @Model.EntityOR.Staff.Person.FirstName
                    @Html.Raw("&nbsp;")
                    @Model.EntityOR.Staff.Person.OtherNames
                }
                &nbsp;
            </td>
            <td>
                @if (Model.ReviewdBy != null)
                {
                    @Model.ReviewdBy.Person.FirstName 
                    @Html.Raw("&nbsp;")
                    @Model.ReviewdBy.Person.OtherNames
                }
            </td>
            <td>
                @if (Model.AuthorizdBy != null)
                {
                    @Model.AuthorizdBy.Person.FirstName 
                    @Html.Raw("&nbsp;")
                    @Model.AuthorizdBy.Person.OtherNames
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Title:
            </td>
            <td>
                @Model.PreparedBy.Designation.Name
            </td>
            <td>
                @if (Model.EntityOR.Staff != null)
                { 
                    @Model.EntityOR.Staff.Designation.Name
                }
                &nbsp;
            </td>
            <td>
                @if (Model.ReviewdBy != null)
                {
                    @Model.ReviewdBy.Designation.Name
                }
            </td>
            <td>
                @if (Model.AuthorizdBy != null)
                {
                    @Model.AuthorizdBy.Designation.Name
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Date:
            </td>
            <td>
                @Model.PreparedOn.ToString("dd/MM/yyyy h:mm tt")
            </td>
            <td>
                @if (Model.EntityOR.Staff != null)
                { 
                    @Model.EntityOR.ApprovedOn.Value.ToString("dd/MM/yyyy h:mm tt")
                }
                &nbsp;
            </td>
            <td>
                @if (Model.ReviewdBy != null)
                {
                    @Model.ReveiwDate.ToString("dd/MM/yyyy h:mm tt")
                }
            </td>
            <td>
                @if (Model.AuthorizdBy != null)
                {
                    @Model.AuthorizDate.ToString("dd/MM/yyyy h:mm tt")
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                @Resources.Global_String_Signature:
            </td>
            <td>
                @if (Model.PreparedBy.Person.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.PreparedBy.Person.Id, area = "" })" alt="" style="max-width: 100px;" />
                }
            </td>
            <td>
                @if (Model.EntityOR.Staff != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.EntityOR.Staff.Person.Id, area = "" })" alt="" style="max-width: 100px;" />
                }
                &nbsp;
            </td>
            <td>
                @if (Model.ReviewdBy != null && Model.ReviewdBy.Person.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.ReviewdBy.Person.Id, area = "" })" alt="" style="max-width: 100px;" />
                }
            </td>
            <td>
                @if (Model.AuthorizdBy != null && Model.AuthorizdBy.Person.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.AuthorizdBy.Person.Id, area = "" })" alt="" style="max-width: 100px;" />
                }
            </td>
        </tr>
    </table>
    @if (Model.BudgetCheckResults != null && Model.BudgetCheckResults.Count > 0)
    {
        <br />
        <center style="text-align: center; color: Red; font-weight: bold; font-style: italic;">@Resources_frank.OrderRequest_ViewOrderRequestItems_FundsUnavailableMessage</center>
        <table align="center" class="cardTable">
            <tr>
                <th>@Resources.Budget_CategoryList_ProjectNo</th>
                <th>@Resources.Budget_CreateSubLine_LineNumber</th>
                <th>@Resources.MasterBudget_MasterBudget_FundsAvailable</th>
                <th>@Resources_frank.OrderRequest_ViewOrderRequestItem_AmountChecked</th>
            </tr>
            @foreach (var bcr in Model.BudgetCheckResults)
            {
                <tr>
                    <td>@bcr.ProjectBudget.BudgetCategory.ProjectDonor.ProjectNumber</td>
                    <td>@bcr.ProjectBudget.LineNumber @bcr.ProjectBudget.Description</td>
                    <td style="color: Red; font-weight: bold;" align="right">@bcr.AvailableAmount.ToString("#,##0.00")</td>
                    <td align="right">@bcr.AmountChecked.ToString("#,##0.00")</td>
                </tr>
            }
        </table>
    }
    
    <input type="hidden" id="actionStatus" value="@ViewBag.Response" />
    <input type="hidden" id="statusMsg" value="@ViewBag.msg" />
    @if (Model.CanEdit && Model.ORDetails.Count > 0)
    { 
        <table width="98%" align="center">
            <tr>
                <td align="right" width="100%">
                    <input type="button" class="btn green" value="  @Resources.Global_String_SubmitForApproval  " onclick="if(confirm('@Resources.Global_String_SubmitForApproval?')){sendRequest('SubmitOR/@Model.EntityOR.Id', 'requestDiv', 'loading'); document.getElementById('requestItemDiv').innerHTML='';if (document.getElementById('table') != null) {initSorter();sorter.size(50);LoadRequests();}}" />
                </td>
            </tr>
        </table>
    }
    else if (Model.EntityOR.IsAuthorized == true && UserContext.HasPermission(StandardPermissionProvider.OrderRequestPrint))
    {
        <hr />
@*<a class="btn btn-primary" target="_blank" href="/Reports/OrderRequest/ViewOrder/@Model.EntityOR.Id" style="margin-left: 48%; margin-bottom: 2%;">
            Get Pdf of OR</a>*@
       
        <a class="btn btn-primary" href="@Url.Action("pdf", "OrderRequest", new { area = "Reports", orId = Model.EntityOR.Id })" target="_blank" style="margin-left: 48%; margin-bottom: 2%;">
            @Resources.Budget_ViewBudget_DownloadPdf</a>
        <br />
    }
    else
    { 
        <br />
    }
</div>
<br />
<p>
    @Ajax.ActionLink(Resources.Global_String_BackToList, "Index", new { id = "ViewOrderRequests" }, new AjaxOptions
    {
        UpdateTargetId = "requestDiv",
        LoadingElementId = "loading",
        Url = Url.Action("ViewOrderRequests"),
        OnSuccess = "if (document.getElementById('table') != null) {initSorter();sorter.size(50);}"
    })
</p>
